package edu.cuit.springboot201.controller;

import edu.cuit.springboot201.model.StudentScore;
import edu.cuit.springboot201.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    private ScoreService service;

    @Value("${proj.title}")
    private String projTitle;

    @RequestMapping("")
    public String viewScorePage(ModelMap model) {
        model.addAttribute("projTitle", projTitle);
        return "score_vue";
    }

    @ResponseBody
    @RequestMapping("/queryScore")
    public List<StudentScore> queryScore(String stuNo, String course) {
        List<StudentScore> scoreList = service.queryScore(stuNo, course);
        //JSONArray scoreArray = ScoreUtil.scoreListToJsonArray(scoreList);
        return scoreList;
    }

    @ResponseBody
    @RequestMapping("/saveScore")
    public void saveScore(StudentScore score) {
        System.out.println(score);
        score.setDate(new Date());
        service.saveScore(score);
    }

}
